package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.warn.DevWarnDetailInfo;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/8/12.
 */

public class GetWarnDetailInfoRequest extends Request<DevWarnDetailInfo> {
    private long efairydevicemsg_id;
    public GetWarnDetailInfoRequest(long efairydevicemsg_id,Response.Listener<DevWarnDetailInfo> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/alarmrecord"), listener);
        this.efairydevicemsg_id = efairydevicemsg_id;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());
        addParam("access_token", CacheManager.getAccessToken());
        addParam("efairydevicemsg_id", String.valueOf(efairydevicemsg_id));
        return super.getParams();
    }

    @Override
    protected DevWarnDetailInfo parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<DevWarnDetailInfo>() {
        }.getType());
    }

}
